import { routerRedux } from 'dva/router';
import { stringify,} from 'qs';
import {
  getShopSmsHistory,
  updateSmsSendState,
  trueAccountLogin
} from '@/services/http';

import { setValueWithLocalStorage } from '@/utils/authority';


export default {
  namespace: 'sms',
  state: {
    total: 0,
    isLoading: true,
    historyList:[],
  },

  effects: {

    *getShopSmsHistory(payload, { call, put }) {
      const response = yield call(getShopSmsHistory, payload.payload);
      yield put({
        type: '_getShopSmsHistory',
        data: response,
      })

    },

    *updateSmsSendState(payload, { call, put }) {
      const response1 = yield call(updateSmsSendState, payload.payload);
      const {callback} = payload.payload;
      const response2 = yield call(trueAccountLogin, payload.payload);
      setValueWithLocalStorage('userinfo',response2.ret);
      callback(response1)
    },

  },

  reducers: {
    _getShopSmsHistory(state, action) {
      return {
        ...state,
        historyList: action.data.code == 1 ? action.data.ret : [],
        total: action.data.code == 1 ? action.data.total : 0,
        isLoading: false,
      };
    },

  },
};
